#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建一个老师对象
    this->tea = new teacher(this);

    //创建一个学生对象
    this->stu = new student(this);

    //老师下课，学生请吃饭
    //connect(tea, &teacher::hungry, stu, &student::treat);

    //调用下课函数
    QPushButton* btn = new QPushButton("请老师吃饭", this);

    btn->move(100, 100);

    connect(btn, &QPushButton::clicked, this, &Widget::classIsover);

    //连接带参的信号和槽
    //指针->地址
    //函数指针->函数地址
    void(teacher:: *teachersignal)(QString) = &teacher::hungry;
    void(student:: *studentSolt)(QString) = &student::treat;

    connect(tea, teachersignal, stu, studentSolt);
    classIsover();

}

void Widget::classIsover()
{
    //下课函数，调用后 出发老师饿了的信号
    emit tea->hungry("水盆羊肉");
}

Widget::~Widget()
{
    delete ui;
}
